from exts import db

class TestModel(db.Model):
    __tablename__ = "test"
    id = db.Column(db.Integer,primary_key = True,autoincrement=True)
    name = db.Column(db.String(100),nullable=False)
    # sign = db.Column(db.String(100),nullable=False)

    def insert(self,record):
        db.session.add(record)
        db.session.commit()
    
    def delete_by_id(self,id):
        record = self.query.get(id)
        db.session.delete(record)
        db.session.commit()

    def update_by_id(self,id,name):
        record = self.query.get(id)
        record.name = name
        db.session.commit()

    def select_by_id(self,id):
        record = self.query.get(id)
        return record
    
    def select_by_name(self,name):
        record = self.query.filter_by(name=name).first()
        return record

    #     user = User.query.filter_by(username="张三").first() # 若为空，返回NULL
    # user.password = "22222222"
    # db.session.commit()